//
//  KFDModelObject.m
//  KFD
//
//  Created by JIRENTIANXIANG on 6/6/15.
//  Copyright (c) 2015 KFD. All rights reserved.
//

#import "KFDModelObject.h"

@implementation KFDModelObject

+(instancetype)modelObjectFromDictionary:(NSDictionary *)dictionary
{
    return [[[self class] alloc] initWithDictionary:dictionary];
}

-(instancetype)initWithDictionary:(NSDictionary *)dictionary
{
    if ((self=[super init])&&![dictionary isKindOfClass:NSNull.class]) {
        for (NSString* key in dictionary.keyEnumerator) {
            id value=dictionary[key];
            if (![value isKindOfClass:[NSNull class]]) {
                SEL selector=NSSelectorFromString(key);
                if ([self respondsToSelector:selector]&&![NSObject instancesRespondToSelector:selector]) {
                    @try {
                        [self setValue:dictionary[key] forKey:key];
                    }
                    @catch (NSException *exception) {
                        
                    }
                    @finally {
                        
                    }
                }
            }
        }
    }
    return self;
}

-(NSNumber*)numberFromString:(NSString *)string
{
    if (string&&string.length>0) {
        NSNumber* number=@(string.floatValue);
        return number;
    }else{
        return nil;
    }
}

@end
